#!/bin/bash

# Set the content-type header
echo "Content-type: text/html"
echo ""

# Fetch the origin header (convert to lowercase for consistency)
origin=$(echo "$REMOTE_ADDR" | tr '[:upper:]' '[:lower:]')

# Extract the domain from the origin (remove "http://", "https://", and any trailing path)
# domain=$(echo "$origin" | sed -e 's|https\?://||' -e 's|/.*||')

# Normalize the domain (remove the TLD)
# domain=$(echo "$domain" | sed -e 's|\.[^.]*$||')

# Define allowed domain (case-insensitive, without TLD)
allowed_domain="198.12.124.158"  # Adjust this to the domain you want to allow, e.g., "domain"

# Normalize the allowed domain for comparison
# normalized_allowed_domain=$(echo "$allowed_domain" | tr '[:upper:]' '[:lower:]')

# Check if the origin domain matches the allowed domain
if [ "$origin" == "$allowed_domain" ]; then
    # Fetch the content from the target URL using curl
    URL="https://github.com/freeCodeCamp/freeCodeCamp"
    curl -s "$URL"
else
    echo "<h1>Access Denied</h1><p>Invalid origin domain...$domain</p>"
fi

# http://198.57.45.16/cgi-bin/testxmlcgi.out





